import random

def guess_number():
    target = random.randint(1, 100)
    attempts = 0

    while True:
        try:
            guess = int(input("请输入一个1到100之间的整数："))
        except ValueError:
            print("输入错误，请输入一个整数。")
            continue

        attempts += 1

        if guess < target:
            print("猜小了！")
        elif guess > target:
            print("猜大了！")
        else:
            print(f"恭喜你，猜对了！答案是{target}，你共猜了{attempts}次。")
            break

if __name__ == "__main__":
    guess_number()
